package org.videopractice.network.message;

import org.videopractice.common.StringUtils;

public class Message {

    /** 消息ID长度 **/
    public static final int MSGID_LENGTH = 32;

    /** 消息编码 */
    private MessageCode code;

    /** 消息ID */
    private String msgId;

    /** 消息体 */
    private String body;

    public Message() {}

    public Message(MessageCode code) {
        this.code = code;
    }

    public Message(MessageCode code, String body) {
        super();
        this.code = code;
        this.msgId = GUID.generateByUUID();
        this.body = StringUtils.toString(body);
    }

    public Message(MessageCode code, String msgId, String body) {
        super();
        this.code = code;
        this.msgId = msgId;
        this.body = StringUtils.toString(body);
    }

    public MessageCode getCode() {
        return code;
    }

    public void setCode(MessageCode code) {
        this.code = code;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Message [code=").append(code)
                .append(", msgId=").append(msgId)
                .append(", body=").append(body).append("]");
        return builder.toString();
    }

} 
